home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: new and delete with arrays
- Date: 17 Feb 1996 17:05:42 +0100
- Organization: Fachbereich Informatik, TH Darmstadt
- Sender: enno@kitz.inferenzsysteme.informatik.th-darmstadt.de
- Message-ID: <ltbumyey3t.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <4g4loa$i1l@mordred.gatech.edu>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: Darin Heuermann's message of 17 Feb 1996 13:38:18 GMT
- X-Newsreader: Gnus v5.1
-
- In article <4g4loa$i1l@mordred.gatech.edu> Darin Heuermann <gt1792a@prism.gatech.edu> writes:
-
- When I allocate an array of classes with delete, should delete call all of
- the instances' destructors? Here is an example of what I mean.
-
- //**********************************************
-
- class MYCLASS {
- public:
- MYCLASS(void);
- ~MYCLASS(void);
- } // MYCLASS
-
- MYCLASS *myClass;
-
- myClass = new MYCLASS[10];
- delete myClass;
-
- //**********************************************
-
- I would expect all 10 instances to call ~MYCLASS() when delete myClass is
- called, but only the first instance's destructor is being called. Is the
- a bug in the compiler or is this how it's supposed to work?
-
- The behavior of this code is undefined. You have to use 'delete[] myClass;'
- instead.
-
- Enno
-